package StackAndQueue;

import java.io.CharArrayWriter;
import java.util.Stack;
import java.util.stream.Collectors;

/**
 * @ Author     ：侯耀祖
 * @ Description：
 */
public class removeDuplicates {
    public String removeDuplicates(String s) {
        Stack<Character> stack = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if (stack.isEmpty() || stack.peek() != ch){
                stack.push(ch);
            } else {
                stack.pop();
            }
        }
        return stack.stream()
                .map(String::valueOf) // 将Character对象转换为String
                .collect(Collectors.joining());
    }
}
